package algorithm.easy;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: algorithm.easy
 * @Author: 江岸
 * @CreateTime: 2021-05-15 20:13
 * @Description: 13. 罗马数字转整数
 */
public class RomanToInt13 {
    public int romanToInt(String s) {
        int values[]={1000,900,500,400,100,90,50,40,10,9,5,4,1};
        String reps[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
        int res = 0;
        for (int i=0;i<13;i++){
            while (s.startsWith(reps[i])){
                res+=values[i];
                s = s.substring(reps[i].length());
            }
        }
        return res;
    }
}
